package com.example.filetest;

/*
 * collec终结方法
 * */


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Test06 {
    public static void main(String[] args) {

        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7);

        List<Integer> collected = list.stream().filter(i -> i % 2 == 0).collect(Collectors.toList());
        System.out.println(collected);

        ArrayList<String> strings = new ArrayList<>();
        Collections.addAll(strings, "zhangshan,23", "lisi,24", "wangwu,25");

        Map<String, Integer> collected1 = strings.stream().filter(s -> Integer.parseInt(s.split(",")[1]) >= 24).collect(
                Collectors.toMap(new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split(",")[0];
                    }
                }, new Function<String, Integer>() {
                    @Override
                    public Integer apply(String s) {
                        return Integer.parseInt(s.split(",")[1]);
                    }
                })
        );
        System.out.println(collected1);

    }
}
